{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-18T08:46:59.430741600Z",
     "start_time": "2024-09-18T08:46:59.411875800Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 "
     ]
    }
   ],
   "source": [
    "#猜数字 （上机练习）\n",
    "# isdigit()检查字符串中的所有字符是否都是数字\n",
    "number=100\n",
    "for i in range(number):\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6f411e3ab409dd82",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-18T08:58:11.431620900Z",
     "start_time": "2024-09-18T08:58:11.404575700Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7 14 17 "
     ]
    }
   ],
   "source": [
    "for i in range(1,number+1):\n",
    "    # 判断是否是7的倍数或包含7\n",
    "    if i%7==0 or '7' in str(i):\n",
    "        print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "56a0b04645c3eab3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-18T09:07:27.642740600Z",
     "start_time": "2024-09-18T09:07:27.602826200Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 3 5 "
     ]
    }
   ],
   "source": [
    "num=3\n",
    "for i in range(1,2*num,2):\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "262c7b37",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      *      \n",
      "     ***     \n",
      "    *****    \n",
      "   *******   \n",
      "  *********  \n",
      " *********** \n",
      "*************\n",
      " *********** \n",
      "  *********  \n",
      "   *******   \n",
      "    *****    \n",
      "     ***     \n",
      "      *      \n"
     ]
    }
   ],
   "source": [
    "#长度小于 width，两侧填充空格，新字符串的长度等于 width\n",
    "num=7\n",
    "s = '*'\n",
    "for i in range(1, 2*num, 2):\n",
    "    print((s * i).center(2*num-1))\n",
    "for i in reversed(range(1, 2*num-1, 2)):\n",
    "    print((s * i).center(2*num-1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "163f2d55",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      *\n",
      "     ***\n",
      "    *****\n",
      "   *******\n",
      "  *********\n",
      " ***********\n",
      "*************\n",
      " ***********\n",
      "  *********\n",
      "   *******\n",
      "    *****\n",
      "     ***\n",
      "      *\n"
     ]
    }
   ],
   "source": [
    "num=7\n",
    "for i in range(-(num-1),num):\n",
    "    if i<0:\n",
    "        j=-i\n",
    "    else:\n",
    "        j=i\n",
    "    print(' '*j+'*'*(2*num-1-2*j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "ed9f482e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "1*2=2\t2*2=4\t\n",
      "1*3=3\t2*3=6\t3*3=9\t\n",
      "1*4=4\t2*4=8\t3*4=12\t4*4=16\t\n",
      "1*5=5\t2*5=10\t3*5=15\t4*5=20\t5*5=25\t\n",
      "1*6=6\t2*6=12\t3*6=18\t4*6=24\t5*6=30\t6*6=36\t\n",
      "1*7=7\t2*7=14\t3*7=21\t4*7=28\t5*7=35\t6*7=42\t7*7=49\t\n",
      "1*8=8\t2*8=16\t3*8=24\t4*8=32\t5*8=40\t6*8=48\t7*8=56\t8*8=64\t\n",
      "1*9=9\t2*9=18\t3*9=27\t4*9=36\t5*9=45\t6*9=54\t7*9=63\t8*9=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "#九九乘法表     \n",
    "for i in range(1, 10):\n",
    "    for j in range(1, i + 1):\n",
    "        print(f\"{j}*{i}={j*i}\", end=\"\\t\")\n",
    "    print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
